from dataclasses import dataclass

import os
import string

@dataclass
class SuperParameter_MCD:
    path_number:int=0
    step_number:int=0
    ast_step_number:int=0
    ast_path_max_length:int=0
    channel:int=0
    identifier_max_length:int=0
    legal_chars:str=""
    ast_feature_hidden_dim:int=0
    dfg_feature_hidden_dim:int=0
    
    @property
    def ast_node_dim(self):
        return 5+len(self.legal_chars)
    
    @staticmethod
    def default():
        result=SuperParameter_MCD()
        result.path_number=256
        result.step_number=16
        result.ast_step_number=32
        result.ast_path_max_length=64
        result.identifier_max_length=32
        result.channel=8
        result.legal_chars=string.ascii_letters+string.digits+'_'+'$'
        result.ast_feature_hidden_dim=512
        result.dfg_feature_hidden_dim=512
        return result
    
    @staticmethod
    def SeGra(path_number=256):
        result=SuperParameter_MCD()
        result.path_number=path_number
        result.step_number=64
        result.ast_step_number=32
        result.ast_path_max_length=128
        result.identifier_max_length=32
        result.channel=8
        result.legal_chars=string.ascii_letters+string.digits+'_'+'$'
        result.ast_feature_hidden_dim=256
        result.dfg_feature_hidden_dim=256
        return result
    
    @staticmethod
    def miniSeGra(path_number=256):
        result=SuperParameter_MCD()
        result.path_number=path_number
        result.step_number=32
        result.ast_step_number=32
        result.ast_path_max_length=64
        result.identifier_max_length=24
        result.channel=4
        result.legal_chars=string.ascii_letters+string.digits+'_'+'$'
        result.ast_feature_hidden_dim=512
        result.dfg_feature_hidden_dim=512
        return result

@dataclass
class ModelCachesMeta:
    ast_caches:str=""
    model_file:str=""
    caches_dir:str=""
    dataset_file:str=""
    
    @staticmethod
    def local_ast_caches(local_dir,caches_name=None,caches_dir='caches'):
        
        parent_dir,dir_name=os.path.split(local_dir)
        
        if caches_name is None:
            caches_name=f'{dir_name}_ast_caches.pt'
        
        return os.path.join(parent_dir,caches_dir),os.path.join(parent_dir,caches_dir,caches_name)
    
    @staticmethod
    def local_image_caches(local_dir,caches_name=None,caches_dir='caches'):
        
        parent_dir,dir_name=os.path.split(local_dir)
        
        if caches_name is None:
            caches_name=f'{dir_name}_image_caches.pt'
        
        return os.path.join(parent_dir,caches_dir),os.path.join(parent_dir,caches_dir,caches_name)
    
    @staticmethod
    def local_ast_image_caches(local_dir,caches_name=None,caches_dir='caches'):
        
        parent_dir,dir_name=os.path.split(local_dir)
        
        if caches_name is None:
            caches_name=f'{dir_name}_ast_image_caches.pt'
        
        return os.path.join(parent_dir,caches_dir),os.path.join(parent_dir,caches_dir,caches_name)
    
    @staticmethod
    def default(caches_dir):
        result=ModelCachesMeta()
        result.ast_caches="ast_caches.pt"
        result.model_file="model.pt"
        result.caches_dir=caches_dir
        result.dataset_file="dataset.pt"
        
        return result
    